package com.baboba.rummy.web.client.player;

import java.util.List;

import com.baboba.rummy.card.UserCard;
import com.baboba.rummy.player.Player;
import com.baboba.rummy.player.PlayerEventHandler;
import com.baboba.rummy.web.client.card.CardListView;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Label;

public abstract class PlayerView extends Composite implements PlayerEventHandler{
	protected DockLayoutPanel topPanel;
	protected Direction direction;
	protected CardListView cardView;
	
	public PlayerView(Player player, Direction direction){
		topPanel = new DockLayoutPanel(Unit.PX);
		
		this.direction = direction;
		
		if (direction == Direction.Horizontal){
			Label nameLabel = new Label(player.getName());
			topPanel.addWest(nameLabel, 50);
			
			cardView = new CardListView();
			topPanel.add(cardView);
		}else{
			Label nameLabel = new Label(player.getName());
			topPanel.addNorth(nameLabel, 50);
			
			cardView = new CardListView();
			topPanel.add(cardView);
		}
		
		player.setPlayerHandler(this);
		this.initWidget(topPanel);
	}
	
	@Override
	public void onInitFirstHandCards(List<UserCard> cards) {
		cardView.addNewCards(cards);
	}
	
	public static enum Direction{
		Vertical, Horizontal
	}
}
